<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style/footoo.css" />
<link rel="stylesheet" type="text/css" href="style/ftheader.css" />
<link rel="stylesheet" type="text/css" href="style/ftfooter.css" />
<link rel="stylesheet" type="text/css" href="style/ftcommoncontent.css" />
<script type="text/javascript" src="script/registrasi.js"></script>
<script type="text/javascript" src="script/datetimepicker.js"></script>
<script type="text/javascript" src="script/search.js"></script> 
<script type="text/javascript" src="script/visopt.js"></script> 
<script type="text/javascript" src="script/ajax.js"></script> 
<title>Foo-Too</title>
</head>

<body onload="wow()">
    <div id="headerwrapper">
		<div id = "headerbgfx"></div>
        <div id="footooheader">
        	<div id="footoologo">
            	<a href="#"></a>
            </div>
			<script type="text/javascript">
				setInterval ( "login()", 1000 );
				var sesuatu = 0;
				function getHTTPObject()
				{
					var xmlhttp;
					if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
						try {
							xmlhttp = new XMLHttpRequest();
						} catch (e) {
							xmlhttp = false;
						}
					}
					return xmlhttp;
				};
				
				function login ()
				{
					http = getHTTPObject();
					http.open("GET", "php/login.php?xhttp=true", true);
					
					http.onreadystatechange = function()
					{
						if (http.readyState==4 && http.status==200)
						{
							respon = http.responseText;
							var x;
							if (respon.charAt(0) == '0')
								x = 1;
							else
								x = 2;
							if (x != sesuatu)
							{
								if (x == 1)
								{
									document.getElementById('footooheader').innerHTML= '<div id="footoologo"><a href="#"></a></div>';
									document.getElementById('footooheader').innerHTML+= '<div id="loginarea"><form action="php/auth.php" method="post"><table id="inputLogin"><tr><td class="iltext">Username</td><td><input type="text" name="usr"></td></tr><tr><td class="iltext">Password</td><td><input type="password" name="pass"></td></tr><tr><td></td><td><input type="submit" value="login" /></td></tr></table></form></div>';
									document.getElementById('menunya').innerHTML= '<li><a class="current" onclick="hohoho()">Welcome..</a></li><li><a onclick="hohoho()">Register..</a></li>';
								}
								else
								{
									document.getElementById('footooheader').innerHTML= '<div id="footoologo"><a href="#"></a></div>'+
									'<table class="logouttable"><tr><td class="logouttd"><h1 class="username">'+respon+'</h1><a class="logoutButton" href="php/LogOut.php">Log Out</a></td></tr></table>';
									document.getElementById('menunya').innerHTML= '<li><a href="home.php" class="current">Home</a></li><li><a href="profile.php?'+respon+'">Profile</a></li><li><a href="wall.php?'+respon+'">Wall</a></li><li><a href="fts.php">Photos</a></li><li><a href="message.php">Message</a></li>';
								}
							}
							sesuatu = x;
						}
					};
					http.send();
				}
			</script>
        </div>
        <div id="footoomenu">
            <ul id="menunya">

            </ul>
        </div>
    </div>
    <div id="headermirror">
    	<div id="searchbox">
            <form action="search.php" method="post">
            	<select class="searchselect" name="tipe">
                	<option value="user">User</option>
                	<option value="photo">Photo</option>
                </select>
                <div class="searchbutton">
                    <input id="searchbutton" type="submit" value="" />
                </div>
                <div class="searchtext">
                <input id="searchtext" class="searchtext" type="text" name="searchtext" value="search" onfocus="filledTrue(this.id, 'search')" onblur="filledFalse(this.id, 'search')" />
            	</div>
            </form>		
        </div>
	</div>
	<?php 
		$bewidth = 920; 
		$width = 900;
	?>
    <div id="contentwrapper">
    	<div id="contento">
		<table><tr><td>
			<div id="regregion" rowspan=4>
			</div>
		</td><td>
            <div id="berandareg" style="width:<?php echo $bewidth; ?>px">
                <div class="box" style="width:<?php echo $width; ?>px">Random Users</div>
            	<div id="randomuserarea" style="width:<?php echo $width; ?>px">
                    <?php
						require_once 'php\database.php';
                        $hasil = database::query("SELECT * FROM user WHERE Role = 0 ORDER BY RAND() LIMIT 10");
                        $count = 0;
                        echo '<table><tr>';
                        if (mysql_num_rows($hasil)>0)
                            while ($baris = mysql_fetch_row($hasil))
                            {
                                echo '<td class ="showuser"><a href = "home.php" class="biasa">';
                                if ($baris[8] == NULL) echo '<img src = "'.'images/bg-photo.png'.'" width = "120" height = "120"/><br/>';
                                else
                                {
                                    $id = $baris[8];
                                    $hasil2 = database::query("SELECT * FROM Foto WHERE IDFOTO = $id");
                                    $baris2 = mysql_fetch_row($hasil2);
                                    $string = 'users/'.$baris2[1].'/'.$baris2[2];
                                    echo '<img src="'.$string.'" width = 120 height = 120/>';
                                }
                                if (strlen($baris[0])<=10) echo $baris[0];
                                else
                                    echo substr($baris[0], 0, 10).'...';
                                echo '&nbsp</a></td>';
                                if (++$count % 7==0)
                                    echo '</tr><tr>';
                            }
                        if ($count == 0)
                            echo 'Belum ada user sama sekali (selain admin)';
                        echo '</tr></table>';
                    ?>
				</div>
                <div class="box" style="width:<?php echo $width; ?>px">Newest Photos</div>
                <div id="photoarea" style="width:<?php echo $width; ?>px">
                </div>
				<div class="box" style="width:<?php echo $width; ?>px">Popular Photos</div>
                <div id="photoarea2" style="width:<?php echo $width; ?>px">
                </div>
				<div class="box" style="width:<?php echo $width; ?>px">High Scores</div>
                <div id="photoarea3" style="width:<?php echo $width; ?>px">
                </div>
            </div>
		</td>
		</tr></table>
        </div>
	</div>
    
	<div id="footerwrapper">
    	<div id="footer">
            <div id="footerleft"><br/>
            	ft, ft logoes are trademark of ft company. <br/>
            	Copyright 2010 by : <br/>
                13508011 - M. Albadr Lutan Nasution <br/>
                13508019 - Gregorius Ronny Kaluge <br/>
                13508099 - Alwi Alfiansyah Ramdan <br/>
            </div>
            <div id="footermiddle">
            	
            </div>
            <div id="footerright">
            	
            </div>
        </div>
    </div>
</body>
</html>
<script type="text/javascript">
var gambar = true;
setInterval ( "fotobaru()", 10000);
						
function fotobaru()
{
	http = getHTTPObject();
	http.open("GET", "php/login2.php?fotobaru=true", true);
	http.onreadystatechange = function()
	{
		if (http.readyState==4 && http.status==200)
		{
			respon = http.responseText;
			document.getElementById('photoarea').innerHTML= respon;
		}
	};
	http.send();
}

function popular()
{
	setTimeout ( "popular()", 10000);
	http = getHTTPObject();
	http.open("GET", "php/login2.php?fotopopuler=true", true);
	
	http.onreadystatechange = function()
	{
		if (http.readyState==4 && http.status==200)
		{
			respon = http.responseText;
			document.getElementById('photoarea2').innerHTML= respon;
		}
	};
	http.send();
}

function high()
{
	setTimeout ( "high()", 10000);
	http = getHTTPObject();
	http.open("GET", "php/login.php?high=true", true);
	
	http.onreadystatechange = function()
	{
		if (http.readyState==4 && http.status==200)
		{
			respon = http.responseText;
			document.getElementById('photoarea3').innerHTML= respon;
		}
	};
	http.send();
}

function hohoho()
{
	gambar = !gambar;
	if (!gambar)
	{
		document.getElementById('regregion').innerHTML='<div id="regregion" ><form action="php/register.php" method="post" name="registration"><div class="Box"><p class="judul">Untuk Register lho...</p>Nama<br/><input type="text" id = "nama" name="nama" onblur="hehehe()"/><div id = "validasi_nama"><br/></div>Username<br/><input type="text" name="username" id="username" onblur="hehehe()"/><div id = "validasi_name"><br/></div>Password<br/><input type="password" id = "password" name="password" onblur="hehehe()"/><div id = "validasi_pass"><br/></div>Password Lagi<br/><input type="password" id = "passwordAgain" onblur="hehehe()"/><div id = "validasi_pass2"><br/></div>Tanggal Lahir<br/><input type="text" size="25" id = "tanggalLahir" name="lahir" onblur="hehehe()"/><a href="javascript:NewCal('+"'tanggalLahir','yyyymmdd'"+')"><img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"/></a><div id = "validasi_tgl"><br/></div>Email<br/><input type="text" id = "email" name="email" onblur="hehehe()"/><div id = "validasi_email"><br/></div><button id = "submit" onmouseover="validasi()">Submit</button></div></form></div>';
	}
	else
		document.getElementById('regregion').innerHTML="";
}

function wow()
{
	login();
	fotobaru();
	setTimeout ( "popular()", 500);
	setTimeout ( "high()", 900);
}
</script>